package net.fireox.oa.comm.rtc.listener;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;

import net.fireox.oa.comm.rtc.store.RTCConnectionStore;

public class RTCAsyncContextListener implements AsyncListener {
	
	private String username;
	
	public RTCAsyncContextListener(String username){
		this.username = username;
	}
	
	@Override
	public void onComplete(AsyncEvent event) throws IOException {
		// TODO Auto-generated method stub
		try{
			RTCConnectionStore.poll(username);
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}

	@Override
	public void onTimeout(AsyncEvent event) throws IOException {
		// TODO Auto-generated method stub
		event.getSuppliedResponse().getWriter().print("timeout");
		event.getSuppliedResponse().getWriter().flush();
	}

	@Override
	public void onError(AsyncEvent event) throws IOException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onStartAsync(AsyncEvent event) throws IOException {
		// TODO Auto-generated method stub
		
	}

}
